package com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.entity.Word;

import java.util.ArrayList;
import java.util.List;
import com.real.R;

/**
 * Created with IntelliJ IDEA.
 * User: real
 * Date: 12-7-17
 * Time: 下午9:59
 * To change this template use File | Settings | File Templates.
 */
public class WordAdapter extends BaseAdapter{

    private List<Word> data;
    private Context context;
    private LayoutInflater inflater;

    public WordAdapter(Context context){
        this.context = context;
        this.data = new ArrayList<Word>() {};

        this.inflater = LayoutInflater.from(context);
    }

    public WordAdapter(Context context, List<Word> data){
        this.context = context;
        this.data = data;

        this.inflater = LayoutInflater.from(context);
    }

    public void add(Word word)
    {
        this.data.add(word);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        TextView word, phonetic, meanings;

        Word w = data.get(i);
        if (view == null) {
            view = inflater.inflate(R.layout.cotrol_pushed_word_item, null);
        }

        word = (TextView) view.findViewById(R.id.word_textview);
        word.setText(w.getword());

        phonetic = (TextView) view.findViewById(R.id.phonetic_textview);
        phonetic.setText(w.getphonetic());

        meanings = (TextView) view.findViewById(R.id.meanings_textview);
        meanings.setText(w.getexplain0());

        return view;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return (long)position;
    }
}
